package edu.ynu.se.xiecheng.achitectureclass.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@Where(clause = "is_deleted = 0") //这里的 is_deleted = 0 条件表示在执行查询时，只会查询 is_deleted 字段值为 0 的记录（即未被删除的记录）。
@Table(name = "greenhouse")
public class GreenhouseEntity extends LogicEntity {

    @Column(nullable = false)
    private String boxName;

    @Column(nullable = false)
    private String boxNo;

    @Column
    private String boxAddress;

    @Column
    private Double boxArea;

    @OneToMany(mappedBy = "greenhouse", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonIgnoreProperties("greenhouse") //避免 JSON 序列化时的循环依赖问题。
    private Set<DeviceEntity> devices;
    //cascade = CascadeType.ALL：表示级联所有操作（保存、更新、删除等），即对 GreenhouseEntity 的操作会自动传播到关联的 DeviceEntity 实体上。例如，当删除 GreenhouseEntity 时，关联的 DeviceEntity 也会被删除。
}
